<template>
  <div class="home-container">
    <!-- 轮播横幅 -->
    <div class="banner">
      <div class="banner-content">
        <h1>发现好音乐</h1>
        <p>分享你的音乐，发现更多精彩</p>
        <button @click="toUpload" class="primary-btn">上传音乐</button>
      </div>
    </div>

    <!-- 最新上传 -->
    <div class="section">
      <div class="section-header">
        <h2>最新上传</h2>
        <a href="#" class="see-all" @click.prevent="goToAllMusic">查看全部</a>
      </div>
    </div>

    <!-- 分类导航 -->
    <div class="category-nav" v-if="genres.length > 0">
      <button :class="{ active: currentCategory === 'all' }" @click="currentCategory = 'all'">
        全部
      </button>
      <button
        v-for="genre in genres"
        :key="genre.id"
        :class="{ active: currentCategory === genre.id }"
        @click="currentCategory = genre.id"
      >
        {{ genre.name }}
      </button>
    </div>

    <!-- 音乐列表 -->
    <div class="section">
      <div class="section-header">
        <h2>{{ currentCategory === 'all' ? '全部音乐' : selectedGenreName }}</h2>
      </div>
      <div class="music-grid">
        <div v-for="music in latestMusic" :key="music.id" class="music-card">
          <div class="cover-container" @click.stop="playMusic(music.id, $event)">
            <img
              :src="
                music.coverUrl || 'https://sky-take-ou7.oss-cn-beijing.aliyuncs.com/default.jpeg'
              "
              alt="{{ music.title }}"
              class="cover-img"
            />
            <div class="play-overlay">
              <div class="play-icon">
                <svg
                  width="40"
                  height="40"
                  viewBox="0 0 24 24"
                  fill="none"
                  xmlns="http://www.w3.org/2000/svg"
                >
                  <circle cx="12" cy="12" r="10" fill="rgba(0,0,0,0.5)" />
                  <path d="M9 16V8L16 12L9 16Z" fill="white" />
                </svg>
              </div>
            </div>
          </div>
          <div class="music-info" @click.stop="toMusicDetail(music.id)">
            <h3 class="music-title">{{ music.title }}</h3>
            <p class="music-creator">
              <span v-if="music.creatorName">上传者: {{ music.creatorName }}</span>
              <span v-else>上传者: 未知</span>
            </p>
            <div v-if="music.genres && music.genres.length > 0" class="music-genres">
              <span class="genre-tag" v-for="genre in music.genres" :key="genre.id">
                {{ genre.name }}
              </span>
            </div>
          </div>
        </div>
      </div>
      <div v-if="latestMusic.length === 0" class="empty-state">暂无音乐数据</div>
    </div>
    <!-- 上传类型选择弹窗 -->
    <ElDialog
      v-model="showUploadDialog"
      title="选择上传类型"
      width="30%"
      :before-close="() => (showUploadDialog.value = false)"
    >
      <div class="upload-type-selector">
        <div class="button-group">
          <button
            class="type-button"
            :class="{ active: uploadType === 'single' }"
            @click="uploadType = 'single'"
          >
            上传单曲
          </button>
          <button
            class="type-button"
            :class="{ active: uploadType === 'album' }"
            @click="uploadType = 'album'"
          >
            创建专辑
          </button>
        </div>
      </div>
      <template #footer>
        <button class="cancel-btn" @click="showUploadDialog = false">取消</button>
        <button class="confirm-btn" @click="confirmUpload">确认</button>
      </template>
    </ElDialog>

    <!-- 查看全部音乐弹窗 -->
    <ElDialog
      v-model="showAllMusic"
      :title="`查看全部 - ${selectedGenreName}`"
      width="90%"
      top="5vh"
      :before-close="closeAllMusic"
      custom-class="all-music-dialog"
    >
      <div class="all-music-container">
        <div class="music-grid" v-if="allMusicList.length > 0">
          <div
            v-for="(music, index) in allMusicList"
            :key="music.id"
            class="music-card all-music-card"
            :style="{ '--index': index }"
            @click="toMusicDetail(music.id)"
          >
            <div class="cover-container" @click.stop="playMusic(music.id, $event)">
              <img
                :src="
                  music.coverUrl || 'https://sky-take-ou7.oss-cn-beijing.aliyuncs.com/default.jpeg'
                "
                :alt="music.title"
                class="cover-img"
              />
              <div class="play-overlay">
                <div class="play-icon">
                  <svg
                    width="40"
                    height="40"
                    viewBox="0 0 24 24"
                    fill="none"
                    xmlns="http://www.w3.org/2000/svg"
                  >
                    <circle cx="12" cy="12" r="10" fill="rgba(0,0,0,0.5)" />
                    <path d="M9 16V8L16 12L9 16Z" fill="white" />
                  </svg>
                </div>
              </div>
            </div>
            <div class="music-info">
              <h3 class="music-title">{{ music.title }}</h3>
              <p class="music-creator">
                <span>{{ music.creatorNickname || music.creatorName || '未知创作者' }}</span>
              </p>
              <div v-if="music.genres && music.genres.length > 0" class="music-genres">
                <span class="genre-tag" v-for="genre in music.genres" :key="genre.id">
                  {{ genre.name }}
                </span>
              </div>
            </div>
          </div>
        </div>
        <div v-else-if="loadingMore" class="loading-state">
          <i class="el-icon-loading"></i>
          <span>加载中...</span>
        </div>
        <div v-else class="empty-state">
          <div class="empty-icon">🎵</div>
          <div class="empty-text">暂无音乐数据</div>
          <div class="empty-subtitle">试试其他分类吧～</div>
        </div>

        <div v-if="allMusicList.length > 0 && allMusicList.length < totalMusic" class="load-more">
          <button class="load-more-btn" @click="loadMoreMusic" :disabled="loadingMore">
            <i v-if="loadingMore" class="el-icon-loading"></i>
            {{ loadingMore ? '加载中...' : '加载更多' }}
          </button>
        </div>
      </div>
    </ElDialog>
  </div>
</template>

<script setup>
import { ref, onMounted, computed, watch } from 'vue'
import { ElMessage, ElDialog } from 'element-plus'

import { useRouter } from 'vue-router'
import { getMusicByGenre, getMusicPage, getMusicByGenrePage } from '../api/music'
import { getMainGenres, getGenreByMusicId } from '../api/genre'
import { getUserInfoById } from '../api/user'
import { useUserStore } from '../stores/user'
import { getActivePinia } from 'pinia'
import { eventBus } from '../utils/eventBus'

const router = useRouter()
const pinia = getActivePinia()
const userStore = useUserStore(pinia)
const latestMusic = ref([])
const genres = ref([])
const currentCategory = ref('all')
const loading = ref(true)
const isLoggedIn = computed(() => userStore.isLoggedIn)
const showAllMusic = ref(false)
const allMusicList = ref([])
const currentPage = ref(1)
const pageSize = ref(12)
const totalMusic = ref(0)
const loadingMore = ref(false)

// 获取大类曲风
const fetchGenres = async () => {
  try {
    const res = await getMainGenres()
    console.log('大类曲风数据:', res)

    // 处理API返回格式
    if (res && res.data) {
      if (Array.isArray(res.data)) {
        // 如果直接返回数组
        genres.value = res.data.map((item) => ({
          id: item.id,
          name: item.name,
        }))
      } else if (Array.isArray(res.data.data)) {
        // 如果返回的是{data: [...]}格式
        genres.value = res.data.data.map((item) => ({
          id: item.id,
          name: item.name,
        }))
      } else {
        console.warn('大类曲风数据格式异常:', res)
        genres.value = []
      }
    } else {
      genres.value = []
    }

    console.log('处理后的大类曲风列表:', genres.value)
  } catch (error) {
    // 静默处理404错误，可能是接口不存在或数据为空
    if (error.response?.status !== 404) {
      console.warn('获取曲风分类失败:', error.message || error)
    }
    genres.value = []
  }
}

// 获取单个音乐的三级曲风
const getMusicGenres = async (musicId) => {
  try {
    const res = await getGenreByMusicId(musicId)
    console.log(`音乐${musicId}的三级曲风:`, res)

    if (res && res.data) {
      if (Array.isArray(res.data)) {
        return res.data
      } else if (Array.isArray(res.data.data)) {
        return res.data.data
      }
    }
    return []
  } catch (error) {
    // 静默处理404错误，可能是音乐没有关联曲风
    if (error.response?.status !== 404) {
      console.warn(`获取音乐${musicId}的三级曲风失败:`, error.message)
    }
    return []
  }
}

// 获取最新音乐并补充上传者和曲风信息
const fetchLatestMusic = async () => {
  try {
    loading.value = true
    console.log('当前分类:', currentCategory.value)
    // 根据分类选择不同的API接口
    if (currentCategory.value !== 'all') {
      // 选择了特定曲风，获取该曲风的音乐列表
      const res = await getMusicByGenre(currentCategory.value)
      console.log('曲风音乐数据:', res)
      latestMusic.value = res.data || []
    } else {
      // 选择全部，直接分页查询
      const res = await getMusicPage(1, 12) // 第一页，每页12条
      console.log('全部音乐数据:', res)
      latestMusic.value = res.data?.records || []
    }

    // 为每个音乐项添加上传者名称（支持多个上传者）
    for (const music of latestMusic.value) {
      // 处理上传者名称 - 支持字符串格式的多个ID
      if (music.creatorIds) {
        try {
          // 分割字符串获取ID数组
          const creatorIdArray = music.creatorIds
            .split('-')
            .map((id) => parseInt(id.trim()))
            .filter((id) => !isNaN(id))

          if (creatorIdArray.length > 0) {
            // 查询所有上传者信息 - 静默处理错误，避免401警告
            const creatorPromises = creatorIdArray.map(async (id) => {
              try {
                const userRes = await getUserInfoById(id)
                return userRes.data?.nickname || '未知用户'
              } catch (error) {
                // 静默处理用户信息获取失败，可能是未登录或用户不存在
                if (error.response?.status !== 401) {
                  console.warn(`获取用户${id}信息失败:`, error.message)
                }
                return '未知用户'
              }
            })

            // 等待所有查询完成
            const creatorNicknames = await Promise.all(creatorPromises)
            music.creatorNicknames = creatorNicknames
            music.creatorNickname = creatorNicknames[0] || '未知用户'
            music.creatorNames = creatorNicknames // 保留兼容
            music.creatorName = creatorNicknames.join('、') // 保留兼容
          } else {
            music.creatorNickname = '未知用户'
            music.creatorNicknames = ['未知用户']
            music.creatorName = '未知用户'
            music.creatorNames = ['未知用户']
          }
        } catch (error) {
          console.error('处理上传者信息失败:', error)
          music.creatorName = '未知用户'
          music.creatorNames = ['未知用户']
        }
      } else {
        music.creatorName = '未知用户'
        music.creatorNames = ['未知用户']
      }

      // 添加三级曲风信息
      try {
        const genres = await getMusicGenres(music.id)
        music.genres = genres
      } catch (error) {
        console.error(`获取音乐${music.id}的曲风信息失败:`, error)
        music.genres = []
      }
    }

    console.log('最终音乐列表:', latestMusic.value)
  } catch (error) {
    console.warn('获取最新音乐失败:', error.message || error)
    latestMusic.value = [] // 清空列表避免显示错误数据
  } finally {
    loading.value = false
  }
}

onMounted(() => {
  fetchGenres()
  fetchLatestMusic()
})

// 响应分类变化
watch(() => currentCategory.value, fetchLatestMusic)

// 获取选中的曲风名称
const selectedGenreName = computed(() => {
  if (currentCategory.value === 'all') return '全部音乐'
  const genre = genres.value.find((g) => g.id === currentCategory.value)
  return genre ? genre.name : '未知曲风'
})

// 跳转到查看全部页面
const goToAllMusic = () => {
  router.push({
    path: '/all-music',
    query: {
      category: currentCategory.value,
      genreName: selectedGenreName.value,
    },
  })
}

// 加载全部音乐（分页）
const loadAllMusic = async () => {
  try {
    loadingMore.value = true
    let response

    if (currentCategory.value !== 'all') {
      // 特定曲风的全部音乐
      response = await getMusicByGenrePage(currentCategory.value, currentPage.value, pageSize.value)
    } else {
      // 全部音乐
      response = await getMusicPage(currentPage.value, pageSize.value)
    }

    const musicData = response.data?.records || response.data || []
    totalMusic.value = response.data?.total || 0

    // 处理音乐数据（添加上传者信息）
    for (const music of musicData) {
      await processMusicData(music)
    }

    if (currentPage.value === 1) {
      allMusicList.value = musicData
    } else {
      allMusicList.value.push(...musicData)
    }
  } catch (error) {
    console.warn('加载全部音乐失败:', error.message || error)
  } finally {
    loadingMore.value = false
  }
}

// 处理单个音乐数据（添加上传者和曲风信息）
const processMusicData = async (music) => {
  // 处理上传者信息
  if (music.creatorIds) {
    try {
      const creatorIdArray = music.creatorIds
        .split('-')
        .map((id) => parseInt(id.trim()))
        .filter((id) => !isNaN(id))

      if (creatorIdArray.length > 0) {
        const creatorPromises = creatorIdArray.map(async (id) => {
          try {
            const userRes = await getUserInfoById(id)
            return userRes.data?.nickname || '未知用户'
          } catch (error) {
            // 静默处理用户信息获取失败
            return '未知用户'
          }
        })

        const creatorNicknames = await Promise.all(creatorPromises)
        music.creatorNicknames = creatorNicknames
        music.creatorNickname = creatorNicknames[0] || '未知用户'
        music.creatorName = creatorNicknames.join('、')
      } else {
        music.creatorNickname = '未知用户'
        music.creatorName = '未知用户'
      }
    } catch (error) {
      music.creatorName = '未知用户'
    }
  } else {
    music.creatorName = '未知用户'
  }

  // 添加曲风信息
  try {
    const genres = await getMusicGenres(music.id)
    music.genres = genres
  } catch (error) {
    music.genres = []
  }
}

// 加载更多音乐
const loadMoreMusic = () => {
  if (allMusicList.value.length < totalMusic.value) {
    currentPage.value++
    loadAllMusic()
  }
}

// 关闭查看全部
const closeAllMusic = () => {
  showAllMusic.value = false
  allMusicList.value = []
  currentPage.value = 1
}

const toMusicDetail = (id) => {
  router.push(`/music/${id}`)
}

// 播放音乐
const playMusic = (id, event) => {
  event.stopPropagation()
  console.log('播放音乐:', id)
  // 查找完整的音乐对象
  const music = latestMusic.value.find((item) => item.id === id)
  if (music) {
    // 发送播放事件，传递完整的音乐对象
    eventBus.emit('playMusic', music)
  } else {
    console.error('未找到音乐:', id)
    ElMessage.error('未找到该音乐')
  }
}

// 控制上传类型选择弹窗显示
const showUploadDialog = ref(false)
const uploadType = ref('single') // 默认选择单曲

const toUpload = () => {
  console.log('上传按钮被点击')
  showUploadDialog.value = true
}

// 处理上传类型选择
const confirmUpload = () => {
  showUploadDialog.value = false
  if (uploadType.value === 'single') {
    router.push('/upload?type=single')
  } else {
    router.push('/upload-album')
  }
}

// const formatDuration = (seconds) => {
//   if (!seconds) return '00:00'
//   const mins = Math.floor(seconds / 60)
//   const secs = Math.floor(seconds % 60)
//   return `${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`
// }
</script>

<style scoped>
.home-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 0;
}

/* 轮播横幅样式 */
.banner {
  height: 400px;
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
  border-radius: var(--border-radius);
  margin-bottom: 2rem;
  display: flex;
  align-items: center;
  padding: 0 2rem;
  color: white;
  position: relative;
  overflow: hidden;
}

.banner::before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 50%;
  height: 100%;
  background-image: url('');
  background-size: cover;
  background-position: center;
  opacity: 0.1;
}

.banner-content {
  position: relative;
  z-index: 1;
  max-width: 50%;
}

.banner h1 {
  font-size: 2.5rem;
  margin-bottom: 1rem;
  font-weight: 700;
}

.banner p {
  font-size: 1.2rem;
  margin-bottom: 2rem;
  opacity: 0.9;
}

.primary-btn {
  padding: 0.8rem 2rem;
  background-color: white;
  color: var(--primary-color);
  border: none;
  border-radius: 30px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* 上传类型选择弹窗样式 */
.upload-type-selector {
  padding: 1rem 0;
}

.radio-group {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.radio-label {
  display: flex;
  align-items: center;
  cursor: pointer;
  user-select: none;
}

.radio-input {
  display: none;
}

.radio-button {
  width: 18px;
  height: 18px;
  border: 2px solid #ccc;
  border-radius: 50%;
  margin-right: 0.5rem;
  position: relative;
  transition: all 0.3s ease;
}

.radio-input:checked + .radio-button {
  border-color: var(--primary-color);
}

.radio-input:checked + .radio-button::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--primary-color);
}

.radio-text {
  font-size: 1rem;
  color: #333;
}

.cancel-btn,
.confirm-btn {
  padding: 0.5rem 1.5rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.95rem;
  transition: all 0.3s ease;
}

.cancel-btn {
  background-color: transparent;
  border: 1px solid #ccc;
  color: #666;
  margin-right: 0.5rem;
}

.cancel-btn:hover {
  background-color: #f5f5f5;
}

.confirm-btn {
  background-color: var(--primary-color);
  border: none;
  color: white;
}

.confirm-btn:hover {
  background-color: var(--primary-dark);
}

/* 分类导航样式 */
.category-nav {
  display: flex;
  gap: 1rem;
  margin-bottom: 2rem;
  overflow-x: auto;
  padding-bottom: 1rem;
}

.category-nav button {
  padding: 0.5rem 1rem;
  background-color: transparent;
  border: 1px solid #e0e0e0;
  border-radius: 20px;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.3s ease;
}

.category-nav button.active {
  background-color: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

/* 部分标题样式 */
.section {
  margin-bottom: 3rem;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.section-header h2 {
  font-size: 1.8rem;
  font-weight: 700;
  color: #333;
}

.see-all {
  color: #1db954;
  text-decoration: none;
  font-weight: 500;
}

/* 音乐网格样式 */
.music-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 2rem;
}

.music-card {
  background-color: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  transition: all 0.3s ease;
  cursor: pointer;
}

.music-card:hover {
  transform: translateY(-6px);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.12);
}

.cover-container {
  position: relative;
  width: 100%;
  height: 220px;
  overflow: hidden;
  cursor: pointer;
}

.cover-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
}

.music-card:hover .cover-img {
  transform: scale(1.05);
}

.play-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.2);
  opacity: 0;
  transition: opacity 0.3s ease;
  display: flex;
  justify-content: center;
  align-items: center;
}

.cover-container:hover .play-overlay {
  opacity: 1;
}

.play-icon {
  width: 60px;
  height: 60px;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 50%;
  background-color: rgba(0, 0, 0, 0.6);
  transform: scale(0.8);
  transition: transform 0.3s ease;
}

.cover-container:hover .play-icon {
  transform: scale(1);
}

.music-info {
  padding: 1rem;
  cursor: pointer;
}

.music-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: #333;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.music-creator {
  font-size: 0.85rem;
  color: #666;
  margin: 0 0 0.5rem 0;
}

.music-genres {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.genre-tag {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  font-size: 0.7rem;
  color: var(--primary-color);
  background-color: rgba(29, 185, 84, 0.1);
  border-radius: 12px;
  border: 1px solid rgba(29, 185, 84, 0.2);
  white-space: nowrap;
}

.button-group {
  display: flex;
  gap: 16px;
  width: 100%;
  margin: 20px 0;
}
.type-button {
  flex: 1;
  padding: 24px 16px;
  font-size: 18px;
  border-radius: 12px;
  border: 2px solid #e0e0e0;
  background-color: #ffffff;
  cursor: pointer;
  transition: all 0.3s ease;
}
.type-button:hover {
  border-color: #27ae60;
  background-color: #e8f5e9;
}
.type-button.active {
  border-color: #27ae60;
  background-color: #e8f5e9;
  color: #27ae60;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(39, 174, 96, 0.2);
  transform: translateY(-1px);
}

/* 查看全部弹窗样式 */
.all-music-container {
  max-height: 70vh;
  overflow-y: auto;
  padding: 1rem;
  background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
  border-radius: 12px;
}

/* 自定义滚动条 */
.all-music-container::-webkit-scrollbar {
  width: 8px;
}

.all-music-container::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 4px;
}

.all-music-container::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 4px;
}

.all-music-container::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

.loading-state {
  text-align: center;
  padding: 3rem;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.loading-state i {
  font-size: 2.5rem;
  color: var(--primary-color);
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.empty-state {
  text-align: center;
  color: var(--text-secondary);
  padding: 4rem 2rem;
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.empty-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
  opacity: 0.6;
  animation: bounce 2s infinite;
}

.empty-text {
  font-size: 1.3rem;
  font-weight: 600;
  color: #2c3e50;
  margin-bottom: 0.5rem;
}

.empty-subtitle {
  font-size: 1rem;
  color: #7f8c8d;
  opacity: 0.8;
}

@keyframes bounce {
  0%,
  20%,
  50%,
  80%,
  100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-10px);
  }
  60% {
    transform: translateY(-5px);
  }
}

.load-more {
  text-align: center;
  padding: 2.5rem 0 1rem;
}

.load-more-btn {
  background: linear-gradient(135deg, var(--primary-color), #1ed760);
  color: white;
  border: none;
  padding: 0.875rem 2.5rem;
  border-radius: 30px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(29, 185, 84, 0.3);
  min-width: 150px;
}

.load-more-btn:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--primary-hover), #1db954);
  transform: translateY(-3px);
  box-shadow: 0 6px 20px rgba(29, 185, 84, 0.4);
}

.load-more-btn:active:not(:disabled) {
  transform: translateY(-1px);
}

.load-more-btn:disabled {
  background: #e0e0e0;
  color: #999;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
  .load-more-btn i {
    margin-right: 0.5rem;
  }
}

/* 查看全部音乐卡片特殊样式 */
.all-music-card {
  animation: fadeInUp 0.4s ease-out;
  animation-fill-mode: both;
}

.all-music-card:nth-child(n) {
  animation-delay: calc(0.05s * var(--index, 0));
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.all-music-card:hover {
  transform: translateY(-8px) scale(1.02);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.15);
}

.all-music-card .cover-container {
  position: relative;
  overflow: hidden;
}

.all-music-card .cover-container::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, rgba(29, 185, 84, 0.1), rgba(30, 215, 96, 0.1));
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: 1;
}

.all-music-card:hover .cover-container::before {
  opacity: 1;
}

.all-music-card .cover-img {
  transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.all-music-card:hover .cover-img {
  transform: scale(1.08);
}

.all-music-card .play-overlay {
  background: linear-gradient(135deg, rgba(0, 0, 0, 0.3), rgba(29, 185, 84, 0.2));
  backdrop-filter: blur(2px);
}

.all-music-card .play-icon {
  background: linear-gradient(135deg, rgba(0, 0, 0, 0.7), rgba(29, 185, 84, 0.3));
  border: 2px solid rgba(255, 255, 255, 0.2);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.all-music-card:hover .play-icon {
  background: linear-gradient(135deg, rgba(29, 185, 84, 0.9), rgba(30, 215, 96, 0.9));
  transform: scale(1.1);
  border-color: rgba(255, 255, 255, 0.4);
}

.all-music-card .music-info {
  transition: all 0.3s ease;
}

.all-music-card:hover .music-info {
  background: linear-gradient(135deg, #fafafa, #ffffff);
}

.all-music-card .music-title {
  transition: color 0.3s ease;
}

.all-music-card:hover .music-title {
  color: var(--primary-color);
}

.all-music-card .genre-tag {
  transition: all 0.3s ease;
}

.all-music-card:hover .genre-tag {
  background-color: rgba(29, 185, 84, 0.15);
  border-color: rgba(29, 185, 84, 0.3);
}

/* 响应式布局优化 */
@media (max-width: 768px) {
  .all-music-container {
    padding: 0.5rem;
  }

  .music-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 1rem;
  }

  .cover-container {
    height: 160px;
  }
}

/* 弹窗标题样式 */
.all-music-dialog .el-dialog__header {
  margin: 0;
  padding: 20px 24px;
  border-bottom: 1px solid #f0f0f0;
  background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
  border-radius: 8px 8px 0 0;
}

.all-music-dialog .el-dialog__title {
  font-size: 1.5rem;
  font-weight: 700;
  color: #2c3e50;
  letter-spacing: -0.5px;
}

.all-music-dialog .el-dialog__body {
  padding: 0;
}

.all-music-dialog .el-dialog__close {
  font-size: 1.25rem;
  color: #666;
  transition: all 0.3s ease;
}

.all-music-dialog .el-dialog__close:hover {
  color: var(--primary-color);
  transform: rotate(90deg);
}

/* 查看全部按钮悬停效果 */
.see-all {
  color: var(--primary-color);
  text-decoration: none;
  font-weight: 600;
  position: relative;
  transition: all 0.3s ease;
  padding: 4px 8px;
  border-radius: 4px;
}

.see-all:hover {
  color: var(--primary-hover);
  background-color: rgba(29, 185, 84, 0.1);
  transform: translateX(2px);
}

.see-all::after {
  content: '→';
  margin-left: 4px;
  transition: transform 0.3s ease;
}

.see-all:hover::after {
  transform: translateX(3px);
}
</style>

// 简化版默认测试数据 latestMusic.value = [ { id: 1, title: '测试音乐1', coverUrl:
'https://sky-take-ou7.oss-cn-beijing.aliyuncs.com/default-music-cover.jpg', creatorIds: '1',
creatorName: '测试用户1', creatorNames: ['测试用户1'], genres: ['流行', '电子'] }, { id: 2, title:
'测试音乐2', coverUrl: 'https://sky-take-ou7.oss-cn-beijing.aliyuncs.com/default-music-cover.jpg',
creatorIds: '1-2', creatorName: '测试用户1、测试用户2', creatorNames: ['测试用户1', '测试用户2'],
genres: ['摇滚', '民谣'] }, { id: 3, title: '测试音乐3', coverUrl:
'https://sky-take-ou7.oss-cn-beijing.aliyuncs.com/default-music-cover.jpg', creatorIds: '3',
creatorName: '测试用户3', creatorNames: ['测试用户3'], genres: ['古典', '爵士'] } ]
